package com.cy.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.study.common.Response;
import com.cy.study.req.ExperienceDeleteReq;
import com.cy.study.req.ExperiencePageReq;
import com.cy.study.req.UserExperienceReq;
import com.cy.study.res.ExperienceDetailRes;
import com.cy.study.res.ExperiencePageRes;
import com.cy.study.res.UserExperienceDetailRes;
import com.cy.study.res.UserExperiencePageRes;
import com.cy.study.service.ExperienceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.nimbus.NimbusLookAndFeel;

/**
 * 心得论坛控制器
 */
@RequiredArgsConstructor
@RequestMapping("/experience")
@RestController
@CrossOrigin
@Slf4j
public class ExperienceController {

    private final ExperienceService experienceService;

    /**
     * 管理端心得列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<ExperiencePageRes>> pageExperience(@RequestBody ExperiencePageReq req){
        Page<ExperiencePageRes> res = experienceService.pageExperience(req);
        return Response.success(res);
    }


    /**
     * 管理端心得详情
     * @param experienceId
     * @return
     */
    @GetMapping("/detail/{experienceId}")
    public Response<ExperienceDetailRes> detailExperience(@PathVariable Integer experienceId){
        ExperienceDetailRes res = experienceService.detailExperience(experienceId);
        return Response.success(res);
    }

    /**
     * 管理端删除心得
     * @param req
     * @return
     */
    @PostMapping("/delete")
    public Response deleteExperience(@RequestBody ExperienceDeleteReq req){
        experienceService.deleteExperience(req);
        return Response.success();
    }


    //-----------------用户端


    /**
     * 用户端心得列表
     * @param req
     * @return
     */
    @PostMapping("/userExperiencePage")
    public Response<Page<UserExperiencePageRes>> userExperiencePageRes(@RequestBody UserExperienceReq req){
        Page<UserExperiencePageRes> res = experienceService.userExperiencePageRes(req);
        return Response.success(res);

    }

    /**
     * 用户端心得详情
     */
    @GetMapping("/userExperienceDetail/{exId}")
    public Response<UserExperienceDetailRes> userExperienceDetail(@PathVariable Integer exId){
        UserExperienceDetailRes res = experienceService.userExperienceDetail(exId);
        return Response.success(res);

    }






}
